﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace CjaxExam.Controllers
{
    public class tool
    {
        /// <summary>
        /// 功能描述：返回不重复随机数数组
        /// 作者：    杨艳峰
        /// 创建日期：2006-4-30
        /// </summary>
        /// <param name="Num">随机数个数</param>
        /// <param name="minNum">随机数下限</param>
        /// <param name="maxNum">随机数上限</param>
        /// <returns></returns>
        public int[] GetRandomArray(int Number, int minNum, int maxNum)
        {
            int j;
            int[] b = new int[Number];
            Random r = new Random();
            for (j = 0; j < Number; j++)
            {
                int i = r.Next(minNum, maxNum + 1);
                int num = 0;
                for (int k = 0; k < j; k++)
                {
                    if (b[k] == i)
                    {
                        num = num + 1;
                    }
                }
                if (num == 0)
                {
                    b[j] = i;
                }
                else
                {
                    j = j - 1;
                }
            }
            return b;
        }


        //返回题目类型代号
        public int GetTypeNum(String type) {
            int n = 6;

              if(type=="单选题"){
                  return 1;
              }
              if (type == "多选题")
              {
                  return 2;
              }
              if (type == "判断题")
              {
                  return 3;
              }
              if (type == "填空题")
              {
                  return 4;
              }
              if (type == "主观题")
              {
                  return 5;
              }
              if (type == "其他")
              {
                  return 6;
              }



              return n;
        
        }


        //返回id 标准号码：
        public String getNumID(int i,int length){
            String s = "";

            String i_str = i.ToString();
            char[] c= i_str.ToCharArray();
            if (c.Length >= length)
            {

                s = i_str.Substring(0, length);
                return s;
            }

            else {
                int k = length - c.Length;
                for (int n = 0; n < k;n++ )
                {
                    s = s + "0";
                
                }
                s = s + i_str;

                return s;
            
            }

        }

    }
}
